<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /*
            思路：链表本来就是有序的，因此我们只能重新创建链表
            */
            var sortList = function (head) {
                let p = head
                let arr = []
                while (p) {
                    arr.push(p.val)
                    p = p.next
                }
                arr.sort((a, b) => a - b)
                let dummy = new ListNode()
                let p2 = dummy
                for (let i = 0; i < arr.length; i++) {
                    let node = new ListNode(arr[i])
                    p2.next = node
                    p2 = p2.next
                }
                return dummy.next
            }
        </script>
    </body>
</html>
